package io.finer.erp.jeecg.stock.util;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Vector;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.google.common.collect.Lists;

//扫码PDA相关方法
public class ScanUtil {
	
	/**
	 * @Description 判断是否是托盘编码
	 * @param code
	 * @return
	 * Create at: 2021-02-25 18:27:18
	 * @author: duany
	 * Revision:
	 *    2021-02-25 18:27:18 - first revision by duany
	 *        
	 */
	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
	public static Boolean isTrayCode(String code) {
		if(StringUtils.isBlank(code)) {
			return Boolean.FALSE;
		}
		String[] strArray = StringUtils.split(code, "-");
		if(strArray.length <=2) {
			return Boolean.FALSE;
		}
		String top = strArray[0];
		if(!top.equals("TRAY")) {
			return Boolean.FALSE;
		}
		String mid = strArray[1];
		if(mid.length() != 8) {
			return Boolean.FALSE;
		}
		try {
			sdf.parse(mid); 
		} catch (Exception e) {
			return Boolean.FALSE;
		}
		String last = strArray[strArray.length-1];
		if(last.length() != 6) {
			return Boolean.FALSE;
		}
		return Boolean.TRUE;
	}
	
	public static String changeDateToString(Date date) {
		SimpleDateFormat format = new SimpleDateFormat("ddyyMM");
		if(null != date) {
			return format.format(date);
		}
		
		return StringUtils.EMPTY;
	}
	
	/**
	 * @Description 将list转换为linkedList
	 * @param <T>
	 * @param list
	 * @return
	 * Create at: 2021-05-17 09:45:30
	 * @author: duany
	 * Revision:
	 *    2021-05-17 09:45:30 - first revision by duany
	 *        
	 */
	public static <T> List<T> changeListToLinkedList(Collection<T> list){
		if(null != list) {
			List<T> linkedList = Lists.newLinkedList();
			linkedList.addAll(list);
			return linkedList;
		}
		return null;
	}
	
	public static <T> List<T> changeListToVector(Collection<T> list){
		if(null != list) {
			List<T> vector = new Vector<>();
			vector.addAll(list);
			return vector;
		}
		return null;
	}
}
